home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / file / managers / mc-3.2 / mc-3 / mc-3.2.1 / nt / drive.nt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-17  |  4.2 KB  |  139 lines

  1. /* Ch-Drive command for Windows NT operating system
  2.    
  3.    This program is free software; you can redistribute it and/or modify
  4.    it under the terms of the GNU General Public License as published by
  5.    the Free Software Foundation; either version 2 of the License, or
  6.    (at your option) any later version.
  7.    
  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.
  12.  
  13.    You should have received a copy of the GNU General Public License
  14.    along with this program; if not, write to the Free Software
  15.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  
  16.    
  17.    Bug:
  18.        the code will not work if you have more drives than those that
  19.        can fit in a panel.  
  20.    */
  21.  
  22. #ifndef _OS_NT
  23. #error This file is for the NT operating system.
  24. #else
  25.  
  26. #include <config.h>
  27. #include <windows.h>
  28. #include <string.h>
  29. #include <stdio.h>
  30. #include "tty.h"
  31. #include "mad.h"
  32. #include "util.h"
  33. #include "win.h"
  34. #include "color.h"
  35. #include "dlg.h"
  36. #include "widget.h"
  37. #include "dialog.h"    /* For do_refresh() */
  38.  
  39. #include "dir.h"
  40. #include "panel.h"        /* Needed for the externs */
  41. #include "file.h"
  42. #include "main.h"
  43.  
  44. struct Dlg_head *drive_dlg;
  45. WPanel *this_panel;
  46.  
  47. static int drive_dlg_callback (Dlg_head *h, int Par, int Msg);
  48. static void drive_dlg_refresh (void);
  49. static void drive_cmd();
  50.  
  51. #define B_DRIVE_BASE 100
  52.  
  53. void drive_cmd_a()
  54. {
  55.     this_panel = left_panel;
  56.     drive_cmd();
  57. }
  58. void drive_cmd_b()
  59. {                                  
  60.     this_panel = right_panel;
  61.     drive_cmd();
  62. }
  63.  
  64. static void drive_cmd()            
  65. {
  66.     int  i, nNewDrive, nDrivesAvail;
  67.     char szTempBuf[7], szDrivesAvail[256], *p;    /* mmm... this is bad practice... (256) */
  68.  
  69.     /* Get drives name and count */
  70.     GetLogicalDriveStrings (255, szDrivesAvail);
  71.     for (nDrivesAvail=0, p=szDrivesAvail; *p; nDrivesAvail++) 
  72.         p+=4;
  73.  
  74.     /* Create Dialog */
  75.     do_refresh ();
  76.     drive_dlg = create_dlg ((LINES-6)/2-3,                 /* Center on y */
  77.                 this_panel->widget.x + (this_panel->widget.cols - nDrivesAvail*6)/2,    /* Center on x, relative to panel */
  78.                 6, nDrivesAvail*6, dialog_colors,
  79.             drive_dlg_callback, "[ChDrive]", "drive", DLG_NONE);
  80.     x_set_dialog_title (drive_dlg, "Change Drive");
  81.  
  82.     /* Add a button for each drive */
  83.     for (i = 0; i < nDrivesAvail; i++) {
  84.         p -= 4;
  85.         sprintf (szTempBuf, "[ %c ]", *p);
  86.     add_widgetl (drive_dlg, button_new (3, (nDrivesAvail-i-1)*5+3, B_DRIVE_BASE+(szTempBuf[2]-'A'), 
  87.             szTempBuf, szTempBuf[2], 2, NULL, NULL), XV_WLAY_RIGHTOF);
  88.     }
  89.  
  90.     run_dlg(drive_dlg);   
  91.  
  92.     /* do action */
  93.     if (drive_dlg->ret_value != B_CANCEL) {
  94.     nNewDrive = drive_dlg->ret_value - B_DRIVE_BASE;
  95.         SetCurrentDirectory(szDrivesAvail+(nNewDrive*4));    /* TODO: Should not take you always to root dir*/
  96.         getcwd (this_panel->cwd, sizeof (this_panel->cwd)-2);
  97.         if (*(szDrivesAvail+(nNewDrive*4)) == toupper(*(this_panel->cwd)))  {
  98.              clean_dir (&this_panel->dir, this_panel->count);
  99.            this_panel->count = do_load_dir (&this_panel->dir, this_panel->sort_type, this_panel->reverse, this_panel->case_sensitive, this_panel->filter);
  100.            this_panel->top_file = 0;
  101.            this_panel->selected = 0;
  102.            this_panel->marked = 0;
  103.            this_panel->total = 0;
  104.            show_dir(this_panel);
  105.            reread_cmd();
  106.         } else
  107.                message (1, " Error ", " Can't access drive %s: \n", (szDrivesAvail+(nNewDrive*4)) );
  108.     }
  109.     destroy_dlg (drive_dlg);
  110.     repaint_screen ();
  111. }
  112.  
  113. static int drive_dlg_callback (Dlg_head *h, int Par, int Msg)
  114. {
  115.     char buffer [10];
  116.     
  117.     switch (Msg) {
  118. #ifndef HAVE_X
  119.     case DLG_DRAW:
  120.     drive_dlg_refresh ();
  121.     break;
  122. #endif
  123.     }
  124.     return 0;
  125. }
  126.  
  127. static void drive_dlg_refresh (void)
  128. {
  129.     attrset (dialog_colors[0]);
  130.     dlg_erase (drive_dlg);
  131.     draw_box (drive_dlg, 1, 1, drive_dlg->lines-2, drive_dlg->cols-2);
  132.  
  133.     attrset (dialog_colors[2]);
  134.     dlg_move (drive_dlg, 1, drive_dlg->cols/2 - 7);
  135.     addstr (" Change Drive ");
  136. }
  137.  
  138. #endif
  139.